package cn.bby.jtk.base.exception;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * 业务异常
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class ServiceException extends RuntimeException {
    private static final long serialVersionUID = 1738132149298369906L;
    /**
     * 业务错误码
     */
    private String code = "";

    /**
     * 业务返回数据
     */
    private Serializable data;

    /**
     * http状态码
     */
    private int httpStatus = 200;

    public ServiceException() {
    }

    public ServiceException(String code) {
        this.code = code;
    }

    public ServiceException(String code, String message) {
        super(message);
        this.code = code;
    }

    public ServiceException(String code, int httpStatus) {
        this.code = code;
        this.httpStatus = httpStatus;
    }

    public ServiceException(String code, String message, int httpStatus) {
        super(message);
        this.code = code;
        this.httpStatus = httpStatus;
    }

    public ServiceException(String message, String code, int httpStatus, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.httpStatus = httpStatus;
    }

    public ServiceException(String code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
    }

    public ServiceException(String code, Throwable cause) {
        super(cause);
        this.code = code;
    }

    @Override
    public String toString() {
        return "ServiceException{" +
                "code='" + code + '\'' +
                ", data=" + data +
                ", httpStatus=" + httpStatus +
                ", message=" + this.getMessage() +
                '}';
    }
}
